package com.study.service;

import com.study.dao.CompanyDao;
import com.study.entity.company.Company;
import com.study.util.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author wfw
 * @Date 2020/07/12 15:36
 */
@Service
public class CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Autowired
    private IdWorker idWorker;

    /**
     * 保存公司信息
     */
    public void add(Company company) {
        String id = String.valueOf(idWorker.nextId());
        company.setId(id);
        /**
         * 审核状态 0：未审核，1：已审核
         */
        company.setAuditState("0");
        /**
         * 激活状态 0.未激活，1：已激活
         */
        company.setState(1);
        companyDao.save(company);
    }

    /**
     * 更新公司信息
     */
    public void update(Company company) {
        companyDao.save(company);
    }

    public void deleteById(String id) {
        companyDao.deleteById(id);
    }

    public Company findById(String id) {
        return companyDao.findById(id).get();
    }

    public List<Company> findAll() {
        return companyDao.findAll();
    }
}
